//
//  HBNovelScoreCell.m
//  HeartBeat
//
//  Created by karong on 2023/8/28.
//

#import "HBNovelScoreCell.h"
#import "NSString+Number.h"

@interface HBNovelScoreCell ()
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *scoreImageArray;
@property (weak, nonatomic) IBOutlet UILabel *followLabel;
@property (weak, nonatomic) IBOutlet UIButton *scoreBtn;
@property (weak, nonatomic) IBOutlet UILabel *viewsLabel;
@end

@implementation HBNovelScoreCell
- (void)awakeFromNib {
    [super awakeFromNib];
    [self.scoreBtn setButtonImageTitleStyle:(WSButtonImageTitleStyleRight) padding:6];
}

- (void)setDataWithObject:(HBNovelModel *)object {
    self.scoreLabel.text = SF(@"%.1f", object.score);
    [self setScoreImageWithScore:object.score];
    self.followLabel.text = [NSString ws10Thousands1DecimalWithValue:object.total_favors];
    self.viewsLabel.text = [NSString ws10Thousands1DecimalWithValue:object.total_views];
}


- (void)setScoreImageWithScore:(CGFloat)score {
    for (UIImageView * imageView in self.scoreImageArray) {
        if (score >= 2) {
            imageView.image = IMG(@"icon_xing");
            score -= 2;
            continue;
        }
        if (score > 0) {
            imageView.image = IMG(@"icon_xing2");
            score -= 2;
            continue;
        }
        else {
            imageView.image = IMG(@"icon_xing3");
        }
    }
}

- (IBAction)scoreAction:(id)sender {
    if ([self.delegate respondsToSelector:@selector(novelScoreCellScoreAction)]) {
        [self.delegate novelScoreCellScoreAction];
    }
}
@end
